package zoo2;

import java.util.ArrayList;
import java.util.List;

public class UserCollections implements IUserDataAccess,IDisplayInformation{


    private UserManager areaCorrespondingManager;

    protected List<User> userList;

    //private List<UserStudent> classStudentList;


    public UserCollections() {
        userList = new ArrayList<User>();
    }

    public UserCollections(List<User> animalList){
        this.userList = animalList;
    }

    public UserCollections(UserManager manager ){
        this.areaCorrespondingManager = manager;
        this.userList = new ArrayList<User>();
    }

    public UserCollections(List<User> animalList, UserManager manager ){
        this.areaCorrespondingManager = manager;
        this.userList = animalList;
    }


    @Override
    public boolean addUser(User user) {
        //在列表里增加用户
        return this.userList.add(user);
    }

    @Override
    public boolean deleteUser(User user) {
        //在列表里删除传入的用户对象,
        return this.userList.remove(user);
    }

    @Override
    public boolean deleteUser(String userName) {
        //在列表里删除传入的用户名对应的对象
        return deleteUser(findUser(userName));
    }

    @Override
    public boolean updateUser(User oldUser, User newUser) {
        boolean updateUserSucessed = false;
        if (oldUser == findUser(oldUser.getUserName())){
            if (deleteUser(oldUser)) {
                updateUserSucessed = addUser(newUser);
            }
        }
        return updateUserSucessed;
    }

    @Override
    public User findUser(String userName) {
        User foundUser = null;
        for (User current : this.userList){
            if (current.getUserName().equals(userName)){
                foundUser = current;
            }
        }
        return foundUser;
    }

    @Override
    public String displayAllAnimals() {
        String displayMessageString = "";
        for(User currentUser:this.userList){
            displayMessageString +=currentUser.getUserName();
        }
        return displayMessageString;
    }
}
